﻿using System;
using System.Linq;
using System.Web.UI;
using Test.DAL;
using Test.IDAL;

namespace Test_Stu
{
    public partial class StuInfoUpdate : System.Web.UI.Page
    {
        IStuInfoDAL bll = new StuInfoDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            UnobtrusiveValidationMode = UnobtrusiveValidationMode.None;
            if (!IsPostBack)
            {
                int id = Convert.ToInt32(Request.QueryString["Id"]);
                var info = bll.Single(id);
                if (info != null)
                {
                    Text1.Value = info.Data.Id + "";
                    TextBox1.Value = info.Data.Name;
                    TextBox2.Text = info.Data.content;
                    TextBox3.Text =Convert.ToString(info.Data.Cid);
                }
                else
                {
                    Response.Redirect("~/StuInfo.aspx");
                }

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           Test.Model.StuInfo info = new  Test.Model.StuInfo()
            {
                Id = Convert.ToInt32(Text1.Value),
                Name = TextBox1.Value,
                content = TextBox2.Text,
                Cid=Convert.ToInt32(TextBox3.Text)
            };
            var result = bll.Update(info);
            if (result.States && result.Data > 0)
            {
                Response.Write("<script>alert('修改成功');location='StuInfo.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('" + result.message + "')</script>");
            }
        }
    }
}